package com.steven.string;

import java.io.UnsupportedEncodingException;

public class ReverseString {
	
	public static void reverse (char[] c, int start, int end){
		
		for(end=end-1;start<end;start++,end--){
			
			swap(c,start,end);
		}
		
	}

	private static void swap(char[] c, int start, int end) {
		
		char temp = c[start];		 
	 
		c[start]=c[end];
		c[end]=temp;
		
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		String s = "你好北京";
		char[] c = s.toCharArray();
		
		try {
			byte [] a =  s.getBytes("gbk");
			for(byte b :a ){
				System.out.println("b:"+b);
				
			}
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		System.out.println(s.charAt(2));
		reverse(c,0,c.length);
	 
		System.out.println(new String(c));

	}

}
